//
//  Users.m
//  KYProject
//
//  Created by Mxxx on 2016/12/21.
//  Copyright © 2016年 Roman. All rights reserved.
//

#import "Users.h"
#import <YYModel.h>
@implementation Users
//告诉系统哪些属性要归档
//存
- (void)encodeWithCoder:(NSCoder *)aCoder
{
    unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i ++) {
        Ivar ivar = ivars[i];
        const char *name = ivar_getName(ivar);
        NSString *key = [NSString stringWithUTF8String:name];
        id value = [self valueForKey:key];
        [aCoder encodeObject:value forKey:key];
    }
    free(ivars);
}

//告诉系统哪些属性可以获取
//取
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        unsigned int count = 0;
        Ivar *ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char *name = ivar_getName(ivar);
            NSString *key = [NSString stringWithUTF8String:name];
            id value = [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}

- (NSString *)description
{
    return [self yy_modelDescription];
}

+ (instancetype)userWithDic:(NSDictionary *)dic
{
    Users *user = [[Users alloc]init];
    
    [user setValuesForKeysWithDictionary:dic];
    
    return user;
}
//重写undefine
- (void)setValue:(id)value forKey:(NSString *)key
{
    
}
@end
